<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../static/moment/moment.js"></script>
<script src="../static/moment/locale/zh-cn.js"></script>
<title>物资审核</title>
</head>

<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">物资审核列表</div>
		</div>

	</div>
	<div class="tabs-container">
		<div class="tabs-define">
			<div id="todo" class="active">未审核</div>
			<div id="completed">已审核</div>
		</div>
	</div>
	<div class="table-container" data-options="region:'center'"></div>

	<div style="display: none">
		<div id="displayAtt" class="datagrid-toolbar"
			style="width: 80%; max-height: 80%; padding: 5px; top: 10%; text-align: center;"></div>
	</div>
</body>
<script>
	var currentPro;
	var fromDate = ""; 
	var toDate = ""; 
	var projectitemid = [[${projectitemid}]];

	$(document).ready(function() {
		unreviewed();
		$("#todo").click(function(){
			$(this).siblings().removeClass("active");
			$(this).addClass("active");
			unreviewed();
			})
			$("#completed").click(function(){
				$(this).siblings().removeClass("active");
				$(this).addClass("active");
				reviewed();
			})
		
	});
	function reviewed() {
		$('.table-container').html('<div><table id="reviewed_table" class="easyui-datagrid" style="display:none;min-height: 100%"></table></div>');
			$('#reviewed_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#pro_tb',
			//title:"已审核",
			url : "../reviewed/goods.do",
			method : 'get',
			onSelect : function(index, row) {
				currentPro = row;
			},
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [ {
				field : 'title',
				title : '项目名',
				width : '100%',
				formatter : function(value,row,index) {
					var html='';
					html += '<div class="info-unreviewed">';
					if(row.projectitemchild){
						html+= '<div class="info-item-name" style="width:'+ ellipsis(32) +'px;">'+ row.projectitemchild.name +'</div>';
					}else{
						html+= '<div class="info-item-name" style="width:'+ ellipsis(32) +'px;">'+ row.item.name +'</div>';
					}
					html+= '<div class="info-item-content" style="width:'+ ellipsis(0) +'px;">'+ row.name +'</div>'
					html+= '<div class="info-content">规格：'+ row.specs +'</div>'
					html+= '<div class="info-content" style="width:'+ ellipsis(0) +'px;">'+ row.remark +'</div>'
					html+= '<div class="info-num col-3"><span class="c-yellow"><b>初数</b>'+ row.initial +'<span class="info-unit">/'+ row.unit +'</span></span>'
					html +='<span class="c-blue"><b>末数</b>'+ row.ends +'<span class="info-unit">/'+ row.unit +'</span></span>'
					html +='<span class="c-green"><b>实盘</b>'+ nullNum(row.actual) +'<span class="info-unit">/'+ row.unit +'</span></span></div>'
					if (row.status == 4){
						html += '<div class="info-status ok">已审</div>';
					}
					if (row.status == 3){
						html += '<div class="info-status refuse">已拒绝</div>';
					}
					if (row.status == 6){
						html += '<div class="info-status two">待二级审核</div>';
					}
					if(row.attachments.length>0){
						html+= '<div class="edit"><span class="info-more" onclick="viewAtt1('+index+');"></span></div>'
						}
					html+='</div>'
					return html;
				}
			}] ]
			});
		}
	function unreviewed(){
				$('.table-container').html('<div><table id="unreviewed_table" class="easyui-datagrid" style="display:none;min-height: 100%"></table></div>');
		$('#unreviewed_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : true,
			striped : true,
			//title:"未审核",
			url : "../review/goods.do",
			method : 'get',
			onSelect : function(index, row) {
				currentPro = row;
			},
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [ {
				field : 'title',
				title : '项目名',
				width : '',
				formatter : function(value,row,index) {
					var html='';
					html += '<div class="info-unreviewed">';
					if(row.projectitemchild){
						html+= '<div class="info-item-name" style="width:'+ ellipsis(32) +'px;">'+ row.projectitemchild.name +'</div>';
					}else{
						html+= '<div class="info-item-content" style="width:'+ ellipsis(32) +'px;">'+ row.item.name +'</div>';
					}
					html+= '<div class="info-item-content" style="width:'+ ellipsis(0) +'px;">'+ row.name +'</div>'
					html+= '<div class="info-content">规格：'+ row.specs +'</div>'
					html+= '<div class="info-content">'+ row.remark +'</div>'
					html+= '<div class="info-num col-3"><span class="c-yellow"><b>初数</b>'+ row.initial +'<span class="info-unit">/'+ row.unit +'</span></span>'
					html +='<span class="c-blue"><b>末数</b>'+ row.ends +'<span class="info-unit">/'+ row.unit +'</span></span>'
					html +='<span class="c-green"><b>实盘</b>'+ nullNum(row.actual) +'<span class="info-unit">/'+ row.unit +'</span></span></div>'
					if (row.status == 4){
						html += '<div class="info-status ok">已审</div>';
					}
					if (row.status == 3){
						html += '<div class="info-status refuse">已拒绝</div>';
					}
					if (row.status == 6){
						html += '<div class="info-status two">待二级审核</div>';
					}
					html +='<div class="info-handle clear">'
					html+='<a class="btn-yellow fr" href="#" onclick="updatepro('+index+')">审核</a></div>'
					html+='</div>'
					return html;
				}
			} ] ]
		});
	}
	function ellipsis(value){
		var WIDTH = $("body").width();
		WIDTH-=10;
		var width;
		width = WIDTH-value
		return width;
	}
	function nullNum(value){
		if(value == null){ return value = 0 }else{return value;}
		}
	function refreshProTable() {
		$('#reviewed_table').datagrid("load",{
			startdate:fromDate,
			enddate:toDate,
			projectitemid:projectitemid
		});
		
		$('#unreviewed_table').datagrid("load",{
			projectitemid:projectitemid
		});
	}

	function updatepro(index) {
		var item = $("#unreviewed_table").datagrid('getRows')[index];
		window.location.href = "../appunreviewedadd/goods.do?id=" + item.id;
	}
	
	$("#search").click(function(){
		fromDate = $("#fromDate").datebox('getValue');
		toDate = $("#toDate").datebox('getValue');
		refreshProTable();
	});
	
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(), month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(), hour = date.getHours(), min = date.getMinutes(), sec = date
				.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}

	function viewAtt1(index){
		var row = $('#reviewed_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(isImage(val.url)){
				tb+= '<img onclick="window.open(\'../'+val.url+ 
				'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" '+
				'src="../'+val.url+'" style="width:100px;"><br><span>'+val.name+'</span><br>';
			}else{
				tb+= '<a href="javascript:void(0)" onclick="attachmentFile('+val.id+',\''+val.name+
				'\')"><span>'+val.name+'</span></a><br>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}
	function viewAtt2(index){
		var row = $('#unreviewed_table').datagrid('getRows')[index];
		var tb="";
		$.each(row.attachments,function(i,val){
			if(isImage(val.url)){
				tb+= '<img onclick="window.open(\'../'+val.url+ 
				'\',\'_blank\', \' toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no\');" '+
				'src="../'+val.url+'" style="width:100px;"><br><span>'+val.name+'</span><br>';
			}else{
				tb+= '<a href="javascript:void(0)" onclick="attachmentFile('+val.id+',\''+val.name+
				'\')"><span>'+val.name+'</span></a><br>';
			}
		});
		$('#displayAtt').empty().html(tb);
		$('#displayAtt').dialog({
            title: '附件',
            resizable: true,
            closed: false,
            cache: false,
            modal: true
        });
	}

	function attachmentFile(id,name) {
		$.get('../attachmentFile.do?id=' + id, function(data) {
			blob = new Blob([ data ])
			var a = document.createElement('a');
			a.download = name;
			a.href = window.URL.createObjectURL(blob)
			a.click()
		})
	}
	function isImage(url) {
		var index= url.lastIndexOf(".");
		var ext = url.substr(index+1);
		return [ 'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff' ,'ico'].
				indexOf(ext.toLowerCase()) !== -1;
	}
</script>

</html>